<?php
/**
 * ZView
 *
 * Zend Frameworks View Component for TYPO3
 *
 * @package    ZView
 * @copyright  Copyright (c) Zephir AG, www.zephir.ch
 */

/** Abstract class for extension */
require_once 'Zend/View/Helper/Abstract.php';

/**
 * Helper to retrieve information about (logged in) fe_user.
 *
 * @package ZView
 * @copyright  Copyright (c) Zephir AG, www.zephir.ch
 */
class Tx_Zview_Helper_T3feuser extends Zend_View_Helper_Abstract
{

	/**
	 * @var tslib_feUserAuth
	 */
	private $_feUser;

	/**
	 * @return Tx_Zview_Helper_T3feuser
	 */
	public function t3feuser()
	{
		$this->_feUser = $GLOBALS['TSFE']->fe_user;
		return $this;
	}

	/**
	 * @return boolean
	 */
	public function loggedIn()
	{
		if($this->_feUser instanceof tslib_feUserAuth) {
			if(is_array($this->_feUser->user)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * @param string $key
	 * @return mixed
	 */
	public function data($key = null)
	{
		if($this->loggedIn()) {
			if(is_array($this->_feUser->user)) {
				if(is_null($key)) {
					return $this->_feUser->user;
				}
				if(array_key_exists($key, $this->_feUser->user)) {
					return $this->_feUser->user[$key];
				}
			}
		}
		return null;
	}

}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zview/helper/T3feuser.php']) {
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zview/helper/T3feuser.php']);
}
